#include <bits/stdc++.h>
#define int long long

using namespace std;

const int N = 1e5 + 10;

int n, m;
int a[N];
int aa[N];
int c[N];
int K;
string d[100];
int T;
int x[10];
int win[N];
int ans;
int res[N];
string s[N];

int fun(int x)
{
	for (int i = 1; i <= x; ++ i)
	{
		if ((1 << i) == x) return i;
		if ((1<<i) <= x && (1 << (i + 1)) > x) return i;
	}
}

signed main()
{	
	freopen("arena.in", "r", stdin);
	freopen("arena.out", "w", stdout);
	cin >> n >> m;
	for (int i = 1; i <= n; ++ i )
	{
		scanf("%lld", &aa[i]);
		a[i] = aa[i];
	}
	
	for (int i = 1; i <= m; ++ i )
	{
		scanf("%lld", &d[i]);
	}
	
	for (int i = 1; i <= n; ++ i )
	{
		if ((1 << i) >= n)
		{
			K = i;
			break;
		}
	}
	
	for (int i = 1; i <= K; ++ i )
	{
		cin >> s[i];
	}
	
	cin >> T;
	
	while (T --)
	{
		for (int i = 1; i <= 4; ++ i)
		{
			scanf("%lld", &x[i]);
		}
		for (int i = 1; i <= n; ++ i )
		{
			a[i] = aa[i] ^ x[i % 4 + 1];
		}
		int kk = fun(n);
		while (kk -- )
		{
			int lunshu = 1;
			for (int i = 1; i <= n; ++ i )
			{
				while (i % 2 == 0)
				{
					int cishu = fun(i);
					if (cishu >= lunshu)
						res[lunshu] += i;
				}
			}
			res[lunshu] *= lunshu;
		}
		for (auto i : res)
		{
			ans ^= i;
		}
		cout << ans << endl;
	//	for (int i = 1; i <= m; ++ i )
	//	{
			// qian zhui shi c[i]
		//	do{
		//		int lunshu = 1;
				
			//	memset(win, 0, sizeof win);
				
				//for (int j = 1; j <= c[i]; ++ j )
			//	{
			//		if(d[i][j] == '1')
			//		{
						
			//		}
			//	}
			//	for (int j = 1; j <= c[i]; ++ j)
			//	{
		//			res[i] += win[j];
		//		}
		//		lunshu <<= 1;
		//	}while(lunshu <= c[i]);
			
	//	}
	}
	return 0;
}
